package com.lzc.jobrecomendbackend.controller.recommendation;

import com.lzc.jobrecomendbackend.common.ApiResponse;
import com.lzc.jobrecomendbackend.model.recommendation.PageAdviceRequest;
import com.lzc.jobrecomendbackend.model.recommendation.PageAdviceVO;
import com.lzc.jobrecomendbackend.service.recommendation.RecommendationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 页面智能建议控制器
 */
@RestController
@RequestMapping("/api/advice")
public class PageAdviceController {

    @Autowired
    private RecommendationService recommendationService;
    
    /**
     * 统一的页面智能建议接口
     * 可以根据需要传递页面类型和相关数据
     * 
     * @param request 页面建议请求
     * @return 页面建议响应
     */
    @PostMapping
    public ApiResponse<PageAdviceVO> getPageAdvice(@RequestBody PageAdviceRequest request) {
        PageAdviceVO result = recommendationService.getPageSpecificAdvice(request);
        return ApiResponse.success(result);
    }
    
    /**
     * 技能分析页面智能建议接口
     * 不需要任何参数，直接基于当前技能分析页面的数据生成建议
     */
    @GetMapping("/skill")
    public ApiResponse<PageAdviceVO> getSkillAdvice() {
        PageAdviceRequest request = new PageAdviceRequest();
        request.setPageType("skill");
        request.setData(new HashMap<>()); // 空数据，表示使用后端已有的技能分析数据
        
        PageAdviceVO result = recommendationService.getPageSpecificAdvice(request);
        return ApiResponse.success(result);
    }
    
    /**
     * 薪资分析页面智能建议接口
     * 不需要任何参数，直接基于当前薪资分析页面的数据生成建议
     */
    @GetMapping("/salary")
    public ApiResponse<PageAdviceVO> getSalaryAdvice() {
        PageAdviceRequest request = new PageAdviceRequest();
        request.setPageType("salary");
        request.setData(new HashMap<>()); // 空数据，表示使用后端已有的薪资分析数据
        
        PageAdviceVO result = recommendationService.getPageSpecificAdvice(request);
        return ApiResponse.success(result);
    }
    
    /**
     * 学历分析页面智能建议接口
     * 不需要任何参数，直接基于当前学历分析页面的数据生成建议
     */
    @GetMapping("/education")
    public ApiResponse<PageAdviceVO> getEducationAdvice() {
        PageAdviceRequest request = new PageAdviceRequest();
        request.setPageType("education");
        request.setData(new HashMap<>()); // 空数据，表示使用后端已有的学历分析数据
        
        PageAdviceVO result = recommendationService.getPageSpecificAdvice(request);
        return ApiResponse.success(result);
    }
    
    /**
     * 城市对比页面智能建议接口
     * 不需要任何参数，直接基于当前城市对比页面的数据生成建议
     */
    @GetMapping("/city")
    public ApiResponse<PageAdviceVO> getCityAdvice() {
        PageAdviceRequest request = new PageAdviceRequest();
        request.setPageType("city");
        request.setData(new HashMap<>()); // 空数据，表示使用后端已有的城市对比数据
        
        PageAdviceVO result = recommendationService.getPageSpecificAdvice(request);
        return ApiResponse.success(result);
    }
    
    /**
     * 以下是测试接口，用于测试不同参数下的智能建议效果
     */
    
    /**
     * 技能分析页面智能建议测试接口
     */
    @GetMapping("/test/skill")
    public ApiResponse<PageAdviceVO> testSkillAdvice(
            @RequestParam(required = false) String city,
            @RequestParam(required = false) List<String> skills,
            @RequestParam(required = false) String education,
            @RequestParam(required = false) String experience) {
        
        PageAdviceRequest request = new PageAdviceRequest();
        request.setPageType("skill");
        
        Map<String, Object> data = new HashMap<>();
        if (city != null) data.put("city", city);
        if (skills != null) data.put("skills", skills);
        if (education != null) data.put("education", education);
        if (experience != null) data.put("experience", experience);
        
        request.setData(data);
        
        PageAdviceVO result = recommendationService.getPageSpecificAdvice(request);
        return ApiResponse.success(result);
    }
    
    /**
     * 薪资分析页面智能建议测试接口
     */
    @GetMapping("/test/salary")
    public ApiResponse<PageAdviceVO> testSalaryAdvice(
            @RequestParam(required = false) String position,
            @RequestParam(required = false) String city,
            @RequestParam(required = false) String experience,
            @RequestParam(required = false) String education) {
        
        PageAdviceRequest request = new PageAdviceRequest();
        request.setPageType("salary");
        
        Map<String, Object> data = new HashMap<>();
        if (position != null) data.put("position", position);
        if (city != null) data.put("city", city);
        if (experience != null) data.put("experience", experience);
        if (education != null) data.put("education", education);
        
        request.setData(data);
        
        PageAdviceVO result = recommendationService.getPageSpecificAdvice(request);
        return ApiResponse.success(result);
    }
    
    /**
     * 学历分析页面智能建议测试接口
     */
    @GetMapping("/test/education")
    public ApiResponse<PageAdviceVO> testEducationAdvice(
            @RequestParam(required = false) String education,
            @RequestParam(required = false) String position,
            @RequestParam(required = false) String city) {
        
        PageAdviceRequest request = new PageAdviceRequest();
        request.setPageType("education");
        
        Map<String, Object> data = new HashMap<>();
        if (education != null) data.put("education", education);
        if (position != null) data.put("position", position);
        if (city != null) data.put("city", city);
        
        request.setData(data);
        
        PageAdviceVO result = recommendationService.getPageSpecificAdvice(request);
        return ApiResponse.success(result);
    }
    
    /**
     * 城市对比页面智能建议测试接口
     */
    @GetMapping("/test/city")
    public ApiResponse<PageAdviceVO> testCityAdvice(
            @RequestParam(required = false) List<String> cities,
            @RequestParam(required = false) String position) {
        
        PageAdviceRequest request = new PageAdviceRequest();
        request.setPageType("city");
        
        Map<String, Object> data = new HashMap<>();
        if (cities != null) data.put("cities", cities);
        if (position != null) data.put("position", position);
        
        request.setData(data);
        
        PageAdviceVO result = recommendationService.getPageSpecificAdvice(request);
        return ApiResponse.success(result);
    }
} 